﻿package pluginfw.nio
{
    import pluginfw.*;

    public class Long extends Object
    {
        protected var _high:uint;
        protected var _low:uint;

        public function Long(param1:uint, param2:uint)
        {
            this.init(param1, param2);
            return;
        }// end function

        public function init(param1:uint, param2:uint) : void
        {
            this._high = param1;
            this._low = param2;
            return;
        }// end function

        public function setHigh(param1:uint) : void
        {
            this._high = param1;
            return;
        }// end function

        public function getHigh() : uint
        {
            return this._high;
        }// end function

        public function setLow(param1:uint) : void
        {
            this._low = param1;
            return;
        }// end function

        public function getLow() : uint
        {
            return this._low;
        }// end function

        public function add(param1:Long) : void
        {
            this._high = this._high + param1._high;
            this._low = this._low + param1._low;
            return;
        }// end function

        public function plus(param1:Long) : void
        {
            this._high = this._high - param1._high;
            this._low = this._low - param1._low;
            return;
        }// end function

        public function oppose() : Long
        {
            var _loc_1:* = LongUtils.create(0, 0);
            _loc_1.plus(this);
            return _loc_1;
        }// end function

        public function not() : Long
        {
            return LongUtils.create(~this._high, ~this._low);
        }// end function

        public function and(param1) : Long
        {
            var _loc_2:* = LongUtils.asLong(param1);
            return LongUtils.create(this._high & _loc_2._high, this._low & _loc_2._low);
        }// end function

        public function or(param1) : Long
        {
            var _loc_2:* = LongUtils.asLong(param1);
            return LongUtils.create(this._high | _loc_2._high, this._low | _loc_2._low);
        }// end function

        public function xor(param1) : Long
        {
            var _loc_2:* = LongUtils.asLong(param1);
            return LongUtils.create(this._high ^ _loc_2._high, this._low ^ _loc_2._low);
        }// end function

        public function leftShift(param1:uint) : Long
        {
            param1 = param1 % 64;
            if (param1 == 0)
            {
                return this;
            }
            if (param1 >= 32)
            {
                return LongUtils.create(this._low << param1 % 32, 0);
            }
            return LongUtils.create(this._high << param1 | this._low >>> 32 - param1, this._low << param1);
        }// end function

        public function rightShift(param1:uint, param2:Boolean = false) : Long
        {
            param1 = param1 % 64;
            if (param1 == 0)
            {
                return this;
            }
            if (param1 >= 32)
            {
                if (param2)
                {
                    return LongUtils.create(0, this._high >>> param1 % 32);
                }
                return LongUtils.create((this._high & 2147483648) != 0 ? (uint.MAX_VALUE) : (0), this._high >> param1 % 32);
            }
            if (param2)
            {
                return LongUtils.create(this._high >>> param1, this._low >>> param1 | this._high << 32 - param1);
            }
            return LongUtils.create(this._high >> param1, this._low >> param1 | this._high << 32 - param1);
        }// end function

        public function optimizePositive() : void
        {
            var _loc_1:* = this._low;
            var _loc_2:* = this._high;
            var _loc_3:* = _loc_1 & 1;
            if (_loc_3 == 0)
            {
                this._low = _loc_1 >>> 1 ^ (_loc_2 & 1) << 31;
                this._high = _loc_2 >>> 1;
            }
            else
            {
                this._low = _loc_1 >>> 1 ^ (_loc_2 & 1) << 31;
                this._high = 4294967295 - (_loc_2 >>> 1);
            }
            return;
        }// end function

        public function isZero() : Boolean
        {
            if (this._high == 0)
            {
            }
            return this._low == 0;
        }// end function

        public function toNumber() : Number
        {
            var _loc_1:* = this._high & 2147483648;
            if (_loc_1 > 0)
            {
                return (-Number((4294967295 + 1) - this._high)) * (4294967295 + 1) - this._low;
            }
            return Number(this._high * (4294967295 + 1)) + this._low;
        }// end function

        public function toString() : String
        {
            return "0x" + NumberUtils.makeString(this._high, 8, 16) + NumberUtils.makeString(this._low, 8, 16);
        }// end function

    }
}
